﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace postSale.forms
{
    public partial class processWorkList : processWorkEdit  
    {
        public processWorkList()
        {
            try
            {
                InitializeComponent();
                processCriteria.DisableWorkBy(true);
                processCriteria.mySelectedTaskStatus = common.CommonStatus.Processing;
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }
        public override common.CommonStatus[] myValidTaskStatusList
        {
            get
            {
                return base.myValidTaskStatusList;
            }
            set
            {
                base.myValidTaskStatusList = value;
                processCriteria.myTaskStatusList = this.myValidTaskStatusList;
            }
        }

        protected override void LoadData()
        {
            //Task admin can see all tasks, others can only see their own tasks
            if (!application.SysLibs.isTaskAdminLogin())
            {
                processCriteria.mySelectedWorkById = CommonTypes.Settings.sysLoginInfo.UserId;
                processCriteria.DisableWorkBy(true);
                this.myValidTaskStatusList = new common.CommonStatus[] { common.CommonStatus.Processing, common.CommonStatus.Completed};
            }
            else
            {
                processCriteria.DisableWorkBy(false);
                this.myValidTaskStatusList = null;
            }
            this.myValidTaskStatusList = this.myValidTaskStatusList;
            this.myValidTaskTypeList = this.myValidTaskTypeList;
            
            base.LoadData();
            DoFilter();
        }        
        protected override bool FindData() { ShowFilter(); return true; }
        protected virtual void DoFilter()
        {
            this.tasksSource.Filter = processCriteria.GetCriteria("", false);
            if (processWorkDetail.Visible) processWorkDetail.LoadData();
            this.ShowReccount(tasksSource.Count);
        }
        private void ShowFilter()
        {
            findBtn.Enabled = false;
            taskFilterPnl.Visible = true;
            dataGrid.Height = this.Height - taskFilterPnl.Height -
                              2 * (SystemInformation.CaptionHeight + SystemInformation.BorderSize.Height) - 7;
        }

        private void filterBtn_Click(object sender, EventArgs e)
        {
            try
            {
                DoFilter();
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }
        private void closeFilterBtn_Click(object sender, EventArgs e)
        {
            findBtn.Enabled = true;
            taskFilterPnl.Visible = false;
            dataGrid.Height = this.Height - 2 * (SystemInformation.CaptionHeight + SystemInformation.BorderSize.Height) - 9;
        }
    }
}
